package Hbase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
 * 构造一个实体类存取数据
 * **/
public class OutPut {
    //public static void main(String[] args) throws IOException{
    public  List<Encapsulation> getdata() throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","niit01");

        HTable table = new HTable(conf,"students");
        Scan scan = new Scan();
        ResultScanner rs = table.getScanner(scan);
        List<Encapsulation> encapsulation   =   new ArrayList<>();

        try{
            for (Result result :rs){

                String Name=    Bytes.toString(result.getValue(Bytes.toBytes("Name"),Bytes.toBytes("")));

                String ID = Bytes.toString(result.getRow());

                String Data =   Bytes.toString(result.getValue(Bytes.toBytes("Data"),Bytes.toBytes("")));

                String Number=Bytes.toString(result.getValue(Bytes.toBytes("Number"),Bytes.toBytes("")));

                String Status=Bytes.toString(result.getValue(Bytes.toBytes("Status"),Bytes.toBytes("")));

                String Term =Bytes.toString(result.getValue(Bytes.toBytes("Term"),Bytes.toBytes("")));

                Encapsulation encapsulation11 = new Encapsulation(Name,ID,Data,Number,Status,Term);

                encapsulation.add(encapsulation11);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //System.out.println(encapsulation);
        return encapsulation;
    }
}